import Vue from 'vue'
import Vuex from 'vuex'
import {getHeader} from "../js/common.js"
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    showFlag: 1,
    headerAnimate: "",
    title: "预警管理",
    headerType: 0,
    peopleList: false,
    loadingShow: false,
  },
  mutations: {
    _showFlag(state, val){
      state.showFlag = val;
    },
    _headerAnimate(state, val){
      state.headerAnimate = val;
    },
    _title(state, val){
      state.title = val;
    },
    _headerType(state, val){
      state.headerType = val;
    },
    _peopleList(state, val){
      state.peopleList = val;
    },
    _loadingShow(state, val){
      state.loadingShow = val;
    },
  },
  getters: {
    showFlag_get(state){
      state.title = getHeader.init(state.showFlag);
      return state.showFlag;
    },
    headerAnimate_get(state){
      return state.headerAnimate;
    }
  },
  actions: {
    showFlag_action(context, val){
      context.commit("_showFlag", val);
    },
    headerAnimate_action(context, val){
      if (val) {
        context.commit("_headerAnimate", "header-back");
      } else {
        context.commit("_headerAnimate", "header-forward");
      }
      setTimeout(() => {
        context.commit("_headerAnimate", "");
      }, 500);
    }
  }
})
